package edu.java.texbooks.scjp.threads.test03;

public class MyThread extends Thread {
	private static final int TIME_INTERVAL = 100;

	@Override
	public void run() {
		String threadName = Thread.currentThread().getName();
		System.out.printf("Start %s.\n", threadName);

		// day 1
		LifeCicleOfThread(1);

		// day 2
		System.out.printf("%s wakes up.\n", threadName);
		LifeCicleOfThread(2);

		System.out.printf("Finish %s.\n", threadName);
	}

	private void LifeCicleOfThread(int day) {
		String threadName = Thread.currentThread().getName();
		try {
			System.out.printf("Day %d for %s.\n", day, threadName);
			System.out.printf("%s goes to sleep.\n", threadName);
			Thread.sleep(TIME_INTERVAL);
		} catch (InterruptedException ie) {
			System.out.printf("Error in interrupting of %s.\n", threadName);
		}
	}
}
